<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>When Good Tests Go Bad</title>
    <link rel="stylesheet" type="text/css" href="fitweb.css"/>
    <script type="text/javascript" src="support.js"></script>
    <style type="text/css">
        ul {
            font-weight: bold;
            margin: 5px;
            padding: 0;
        }

        li {
            font-weight: normal;
            margin: 5px 15px;
        }
    </style>
</head>
<body>
<h1 class="title" onclick="toggle();" >When Good Tests Go Bad</h1>

<h4>Run this test and look at the nicely formatted results for some common examples of failing tests, and some tips for fixing them</h4>
<table class="setup pageFixture">
    <tr>
        <td>org.fitweb.fixture.WebFixture</td>
    </tr>
</table>
<h2>Browsing Failures</h2>

<h3>File not found</h3>
<table>
    <tr>
        <td>browse</td>
        <td>file://${user.dir}/tests/data/dodgyFileName.html</td>
    </tr>
</table>
<ul>
    To fix:
    <li>Try accessing the file directly through your browser, to check the URL. Use the expanded URL from the error message.</li>
</ul>
<h2>Component Failures</h2>
<h3>Assertion failures</h3>
<table>
    <tr>
        <td>browse</td>
        <td>file://${user.dir}/tests/Very Short Test.html</td>
    </tr>
</table>
<table>
    <tr>
        <td>assert</td>
        <td class="name">Title</td>
        <td>contains</td>
        <td class="value">Example HTML Page</td>
    </tr>
</table>
<ul>
    To fix:
    <li>Read the error message under the table (you can only see this here if you ran the test).</li>
    <li>This <em>might</em> be an asynchronicity problem, if the change you are testing for was caused by an AJAX call. If so, use "wait for"/"to contain" instead of "assert"/"contains"</li>
    <li>Otherwise, you have just found a bug in your code.</li>
</ul>
<h3>Missing element failures</h3>
<table class="setup">
    <tr>
        <td>define element</td>
        <td class="name">Pet's Name</td>
        <td>as</td>
        <td>//li/input[@name='pet']</td>
    </tr>
</table>
<table>
    <tr>
        <td>assert</td>
        <td class="name">Pet's Name</td>
        <td>contains</td>
        <td class="value">Boris</td>
    </tr>
</table>
<ul>
    To fix:
    <li>The xpath may be incorrect, or too complicated for WebDriver</li>
    <li>Asynchronicity, again</li>
    <li><em>Another</em> bug in your code</li>
</ul>
<h2>Asynchronicity Failures</h2>

<h2>Etcetera</h2>
<table>
    <tr>
        <td><i>expected test results</i></td>
        <td>3</td>
        <td><i>right</i></td>
        <td>2</td>
        <td><i>wrong</i></td>
        <td>0</td>
        <td><i>ignored</i></td>
        <td>2</td>
        <td><i>exceptions</i></td>
    </tr>
</table>
</body>
</html>